<?php
class ZluckyMember extends ObjectModel 
{
	public $id;
	public $id_zgallery_lucky_member;
	public $id_customer;
	public $id_photo;
	public $date_add;
	public $table = 'zgallery_lucky_member';
	
	protected $identifier = 'id_zgallery_lucky_member';
	
	public function getFields ()
	{
		parent::validateFields ();
		$fields['id_zgallery_lucky_member']=(int)($this->id);
		$fields['id_customer']=(int)($this->id_customer);
		$fields['id_photo']=(int)($this->id_photo);
		$fields['date_add']=(int)($this->date_add);
		return $fields;
	}
	
	public function __construct($id=NULL,$id_lang=null){
		parent::__construct ($id,$id_lang);
	}
	
	/**
	 * get list member lucky
	 */
	static public function getMembersLucky () {
		global $cookie;
		$rs = Db::getInstance()->ExecuteS('
			SELECT a.id_zgallery_lucky_member,a.id_customer,b.username as name,pl.name as namePhoto,a.date_add date_add FROM '._DB_PREFIX_.'zgallery_lucky_member a
			LEFT JOIN '._DB_PREFIX_.'customer b ON (a.id_customer=b.id_customer)
			LEFT JOIN '._DB_PREFIX_.'zgallery_photo_lang pl ON (a.id_photo = pl.id_zgallery_photo AND pl.id_lang='.$cookie->id_lang.')
			ORDER BY a.date_add DESC
		');
		return $rs;
	}
	
	static public function createFileCsv () {

		$list = ZluckyMember::getMembersLucky ();

		$fp = fopen(dirname(__FILE__).'/../export/DanhSachThanhVienMayMan.csv', 'w+');
		$arr = array("Danh sach thanh vien may man:");
		fputcsv($fp, $arr);
		$arr = array("STT","ID Customer","Name Customer","Name Photo","Time");
		fputcsv($fp, $arr);
		foreach ($list as $fields) {
		    fputcsv($fp, $fields);
		}
		fclose($fp);
	}
}
